package com.novabluetooth.data;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import com.health.NovaApplication;
import com.health.tablebean.SBCL_DATA;
import com.novabluetooth.services.BluetoothConstant;

import android.text.TextUtils;
import android.util.Log;

/**
 * 保存并显示设备数据
 *
 * @author nova BlueToothData
 */
public class DeviceShowSaveData {
    private static final String TAG = "DeviceShowSaveData";
    static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    static String str_result = "";// 显示结果
    static String devicename = "";// 设备名称
    static String IDCARD = "";
    static String uroString;
    static String bloString;
    static String bilString;
    static String ketString;
    static String leuString;
    static String gluString;
    static String proString;
    static String phString;
    static String nitString;
    static String sgString;
    static String ascString;

    public static String getDataShow(String data, String deviceName) {
        System.out.println(deviceName + ":deviceName");
        str_result = "";
        try {

            IDCARD = NovaApplication.getUserInfo().getIDCARD();
            Log.e(TAG, "获取结果--" + IDCARD);
            if (TextUtils.isEmpty(IDCARD)) {
                return "";
            }

            devicename = deviceName;
            switch (deviceName) {
                case BluetoothConstant.XUEYANG_NOVA:
                    // 诺安血氧
                    if (data.contains(";")) {
                        String xueyangbaohedu = data.split(";")[0].toString();
                        String mailv = data.split(";")[1].toString();
                        str_result = "血氧：" + xueyangbaohedu + "%        " + "脉率：" + mailv + "bpm";

                        if (!checkData("血氧", xueyangbaohedu + "%")) {
                            return str_result;
                        }

                        UUID uuid = UUID.randomUUID();
                        String date = df.format(new Date());
                        // 存血氧
                        saveCLData("诺安血氧仪", "血氧仪", "血氧", xueyangbaohedu + "%", "血氧", uuid.toString(), IDCARD, date);
                        // 存脉率
                        saveCLData("诺安血氧仪", "血氧仪", "脉率", mailv + "bpm", "脉率", uuid.toString(), IDCARD, date);
                        // HealthTiJian_YbqkFragment.showML(mailv);
                    }
                    break;
                case BluetoothConstant.XUETANG_AMX_SANNUO:
                    // 诺安血糖
                    // data="20.11";
                    str_result = "血糖：" + data + "mmol/L";
                    if (!checkData("血糖", data + "mmol/L")) {
                        return str_result;
                    }

                    UUID uuidXueTang = UUID.randomUUID();
                    String dateXueTang = df.format(new Date());
                    // 存血糖
                    saveCLData("诺安血糖仪", "血糖仪", "血糖", data + "mmol/L", "血糖", uuidXueTang.toString(), IDCARD, dateXueTang);
                    Log.e("tag", "测量血糖");
                    // HealthTiJian_FzjcFragment.showXuetang(data);
                    break;
                case BluetoothConstant.XUETANG_WL_1_SANNUO:
                    // 三诺血糖
                    str_result = "血糖：" + data + "mmol/L";
                    if (!checkData("血糖", data + "mmol/L")) {
                        return str_result;
                    }

                    UUID uuidsanNuoXueTang = UUID.randomUUID();
                    String datesanNuoXueTang = df.format(new Date());
                    // 存血糖
                    saveCLData("三诺血糖仪", "血糖仪", "血糖", data + "mmol/L", "血糖", uuidsanNuoXueTang.toString(), IDCARD,
                            datesanNuoXueTang);
                    // HealthTiJian_FzjcFragment.showXuetang(data);
                    break;
                case BluetoothConstant.XUETANG_YUYUE760_YUYUE:
                    // 鱼跃760血糖仪
                    str_result = "血糖：" + data + "mmol/L";
                    if (!checkData("血糖", data + "mmol/L")) {
                        return str_result;
                    }

                    System.out.println(str_result);
                    UUID uuidYuYueXueTang = UUID.randomUUID();
                    String dateYuYueXueTang = df.format(new Date());
                    // 存血糖
                    saveCLData("鱼跃760血糖仪", "血糖仪", "血糖", data + "mmol/L", "血糖", uuidYuYueXueTang.toString(), IDCARD,
                            dateYuYueXueTang);

                    break;
                case BluetoothConstant.XUETANG_WEITAI:
                    // 鱼跃760血糖仪
                    str_result = "血糖：" + data + "mmol/L";
                    if (!checkData("血糖", data + "mmol/L")) {
                        return str_result;
                    }

                    System.out.println(str_result);
                    UUID uuidWeiTaiXueTang = UUID.randomUUID();
                    String dateWeiTaiXueTang = df.format(new Date());
                    // 存血糖
                    saveCLData("微泰血糖仪", "血糖仪", "血糖", data + "mmol/L", "血糖", uuidWeiTaiXueTang.toString(), IDCARD,
                            dateWeiTaiXueTang);

                    break;
                case BluetoothConstant.TIWEN_EWQ_NOVA:
                    // 诺安耳温枪体温
                    str_result = "体温：" + data + "℃";
                    if (!checkData("体温", data + "℃")) {
                        return str_result;
                    }

                    UUID uuidErWen = UUID.randomUUID();
                    String dateErWen = df.format(new Date());
                    // 存体温
                    saveCLData("诺安耳温枪", "耳温枪", "体温", data + "℃", "体温", uuidErWen.toString(), IDCARD, dateErWen);
                    // HealthTiJian_YbqkFragment.showTW(data);
                    break;
                case BluetoothConstant.TIWEN_EWENQ_HTD2:
                    // 诺安耳温枪体温
                    str_result = "体温：" + data + "℃";
                    if (!checkData("体温", data + "℃")) {
                        return str_result;
                    }

                    UUID uuidErWen2 = UUID.randomUUID();
                    String dateErWen2 = df.format(new Date());
                    // 存体温
                    saveCLData("和泰达耳温枪", "耳温枪", "体温", data + "℃", "体温", uuidErWen2.toString(), IDCARD, dateErWen2);
                    // HealthTiJian_YbqkFragment.showTW(data);
                    break;
                case BluetoothConstant.TIZHONG_NOVA:
                    // 诺安体重秤
                    str_result = "体重：" + data + "Kg";
                    if (!checkData("体重", data + "Kg")) {
                        return str_result;
                    }

                    UUID uuidTiZhong = UUID.randomUUID();
                    String dateTiZhong = df.format(new Date());
                    // 存体重
                    saveCLData("诺安体重秤", "体重秤", "体重", data + "Kg", "体重", uuidTiZhong.toString(), IDCARD, dateTiZhong);
                    // HealthTiJian_YbqkFragment.showTZ(data);
                    break;
                case BluetoothConstant.XUEYA_JMR:
                    setXueYaJiData(data, "捷美瑞血压仪");
                    break;
                case BluetoothConstant.XUEYA_JMR2:
                    setXueYaJiData(data, "捷美瑞血压仪");
                    break;
                case BluetoothConstant.XUEYA_MAIBOBO1:
                    //脉搏波血压仪
                    setXueYaJiData(data, "脉搏波血压仪");
                    break;

                case BluetoothConstant.XUEYA_KANGTAI:
                    // 康泰08A血压计
                    setKTXueYaJiData(data);
                    break;
                case BluetoothConstant.XUEHONGDANBAI_NOVA:
                    // 易捷血红蛋白仪
                    String xuehoangBuffer[] = data.split("\r\n");
                    str_result = "血红蛋白：" + xuehoangBuffer[2].substring(8);

                    if (!checkData("血红蛋白", xuehoangBuffer[2].substring(8).toString())) {
                        return str_result;
                    }
                    UUID uuidYJXuehongdanbai = UUID.randomUUID();
                    String dateYJXuehongdanbai = df.format(new Date());
                    // 存血红蛋白
                    saveCLData("易捷血红蛋白仪", "血红蛋白仪", "血红蛋白", xuehoangBuffer[2].substring(8), "血红蛋白",
                            uuidYJXuehongdanbai.toString(), IDCARD, dateYJXuehongdanbai);
                    break;
                case BluetoothConstant.NIAOJI_HT111A_HANTANG:
                    String niaoYeBuffer[] = data.split(",");
                    getNiaoYe(niaoYeBuffer);
                    break;
                case BluetoothConstant.TIWEN_EWQ_HTD:
                    setEWdata(data, BluetoothConstant.TIWEN_EWQ_HTD);
                    break;
                case BluetoothConstant.TIWEN_EWENQ_HTD:
                    setEWdata(data, BluetoothConstant.TIWEN_EWENQ_HTD);
                    break;
                case BluetoothConstant.XUEYA_YOURIEN:
                    // 优瑞恩血压
                    setXueYaJiData(data, "优瑞恩血压仪");
                    break;
                case BluetoothConstant.XUEYA_YE680A_YUYUE:
                    // 鱼跃血压
                    setXueYaJiData(data, "鱼跃血压仪");
                    break;
                case BluetoothConstant.XUEYANG_BM:
                    // 贝瑞血氧
                    if (data.contains(";")) {
                        String xueyangbaohedu = data.split(";")[0].toString();
                        String mailv = data.split(";")[1].toString();
                        str_result = "血氧：" + xueyangbaohedu + "%        " + "脉率：" + mailv + "bpm";

                        if (!checkData("血氧", xueyangbaohedu + "%")) {
                            return str_result;
                        }
                        UUID uuid = UUID.randomUUID();
                        String date = df.format(new Date());
                        // 存血氧
                        saveCLData("贝瑞血氧仪", "血氧仪", "血氧", xueyangbaohedu + "%", "血氧", uuid.toString(), IDCARD, date);
                        // 存脉率
                        saveCLData("贝瑞血氧仪", "血氧仪", "脉率", mailv + "bpm", "脉率", uuid.toString(), IDCARD, date);
                        // HealthTiJian_YbqkFragment.showML(mailv);
                    }
                    break;
                case BluetoothConstant.XUEYANG_LIKANG_KRK:
                    String xueyang = "";
                    String mailv = "";
                    if (data.contains("/")) {
                        xueyang = data.split("/")[0];
                        mailv = data.split("/")[1];
                        str_result = "血氧：" + xueyang + "%        " + "脉率：" + mailv + "bpm";

                        if (!checkData("血氧", xueyang + "%")) {
                            return str_result;
                        }

                        UUID uuid = UUID.randomUUID();
                        String date = df.format(new Date());
                        // 存血氧
                        saveCLData("科瑞康血氧仪", "血氧仪", "血氧", xueyang + "%", "血氧", uuid.toString(), IDCARD, date);
                        // 存脉率
                        saveCLData("科瑞康血氧仪", "血氧仪", "脉率", mailv + "bpm", "脉率", uuid.toString(), IDCARD, date);
                        // HealthTiJian_YbqkFragment.showML(mailv);
                    }
                    break;
                default:
                    break;
            }

        } catch (Exception e) {
            str_result = "";
        }
        return str_result;
    }

    private static String setKTXueYaJiData(String data) {
        if (data.contains(";")) {
            String buffer_kt[] = data.split(";");
            str_result = "高压：" + buffer_kt[0].toString() + "mmHg" + ";低压:" + buffer_kt[1].toString() + "mmHg \n" + "脉率："
                    + buffer_kt[2].toString() + "次/分; \n平均压:" + buffer_kt[3].toString() + "mmHg";

            if (!checkData("高压", buffer_kt[0].toString() + "mmHg")) {
                return str_result;
            }
            UUID uuidJMRXueYa_kt = UUID.randomUUID();
            String dateJMRXueYa_kt = buffer_kt[4].toString();
            // 存高压
            saveCLData("康泰血压计08A-BT", "血压计", "高压", buffer_kt[0].toString() + "mmHg", "高压", uuidJMRXueYa_kt.toString(),
                    IDCARD, dateJMRXueYa_kt);
            // 存低压
            saveCLData("康泰血压计08A-BT", "血压计", "低压", buffer_kt[1].toString() + "mmHg", "低压", uuidJMRXueYa_kt.toString(),
                    IDCARD, dateJMRXueYa_kt);
            // 存脉率
            saveCLData("康泰血压计08A-BT", "血压计", "脉率", buffer_kt[2].toString() + "次/分", "脉率", uuidJMRXueYa_kt.toString(),
                    IDCARD, dateJMRXueYa_kt);
            // 存平均压
            saveCLData("康泰血压计08A-BT", "血压计", "平均压", buffer_kt[3].toString() + "mmHg", "平均压", uuidJMRXueYa_kt.toString(),
                    IDCARD, dateJMRXueYa_kt);
        } else {
            str_result = "";
        }
        return str_result;
    }

    /**
     * 设置血压计数据
     *
     * @param data
     * @param type
     * @return
     * @author 王婷婷
     * @date 2017年10月10日 下午4:20:39
     */
    private static String setXueYaJiData(String data, String type) {
        if (data.contains(";")) {
            String xueYabuffer[] = data.split(";");
            str_result = "高压：" + xueYabuffer[0] + "mmHg" + "；  低压：" + xueYabuffer[1] + "mmHg \n        " + "心率："
                    + xueYabuffer[2] + "次/分";
            if (!checkData("高压", xueYabuffer[0] + "mmHg")) {
                return str_result;
            }
            System.out.println("xueYabuffer:" + xueYabuffer.length);

            UUID uuidYouRuiEnXueYa = UUID.randomUUID();
            String dateYouRuiEnXueYa = df.format(new Date());
            // 存高压
            saveCLData(type, "血压计", "高压", xueYabuffer[0] + "mmHg", "高压", uuidYouRuiEnXueYa.toString(), IDCARD,
                    dateYouRuiEnXueYa);
            // 存低压
            saveCLData(type, "血压计", "低压", xueYabuffer[1] + "mmHg", "低压", uuidYouRuiEnXueYa.toString(), IDCARD,
                    dateYouRuiEnXueYa);
            // 存心率
            saveCLData(type, "血压计", "脉率", xueYabuffer[2] + "次/分", "脉率", uuidYouRuiEnXueYa.toString(), IDCARD,
                    dateYouRuiEnXueYa);
        } else {
            str_result = "";
        }
        return str_result;
    }

    /**
     * 和泰达耳温枪、额温枪
     *
     * @return
     * @author 王婷婷
     * @date 2017年2月13日 下午4:07:10
     */
    private static String setEWdata(String data, String type) {
        if (data.length() < 10) {
            return "";
        }

        String biaozhi = data.substring(3, 5);
        String tiwen = data.substring(5, 9);
        System.out.println(tiwen + "**************");
        UUID uuidEWen = UUID.randomUUID();
        String dateEWen = df.format(new Date());
        if ("00".equals(biaozhi)) {
            str_result = "体温：" + tiwen + "℃";
            if (!checkData("体温", tiwen + "℃")) {
                return str_result;
            }
            if (BluetoothConstant.TIWEN_EWQ_HTD.equals(type)) {
                // 存体温
                saveCLData("和泰达耳温枪", "耳温枪", "体温", tiwen + "℃", "体温", uuidEWen.toString(), IDCARD, dateEWen);
            } else if (BluetoothConstant.TIWEN_EWENQ_HTD.equals(type)) {
                // 存体温
                saveCLData("和泰达额温枪", "额温枪", "体温", tiwen + "℃", "体温", uuidEWen.toString(), IDCARD, dateEWen);
            }
        } else if ("10".equals(biaozhi)) {
            str_result = "表面温度：" + tiwen + "℃";
            if (!checkData("表面温度", tiwen + "℃")) {
                return str_result;
            }

            if (BluetoothConstant.TIWEN_EWQ_HTD.equals(type)) {
                // 存表面温度
                saveCLData("和泰达耳温枪", "耳温枪", "表面温度", tiwen + "℃", "表面温度", uuidEWen.toString(), IDCARD, dateEWen);

            } else if (BluetoothConstant.TIWEN_EWENQ_HTD.equals(type)) {
                // 存表面温度
                saveCLData("和泰达额温枪", "额温枪", "表面温度", tiwen + "℃", "表面温度", uuidEWen.toString(), IDCARD, dateEWen);
            }

        }
        // HealthTiJian_YbqkFragment.showTW(tiwen);
        System.out.println("添加体温");
        return str_result;
    }

    public static String getNiaoYe(String[] niaoYeBuffer) {
        // TODO

        for (int i = 0; i < niaoYeBuffer.length; i++) {
            switch (i) {
                case 1:// 尿胆原
                    int uro = Integer.parseInt(niaoYeBuffer[i]);
                    if (uro == 0) {
                        uroString = "-";
                    } else if (uro == 1) {
                        uroString = "+-";
                    } else if (uro == 2) {
                        uroString = "1+";
                    } else if (uro == 3) {
                        uroString = "2+";
                    } else if (uro == 4) {
                        uroString = "3+";
                    }
                    break;
                case 2:// 潜血
                    int blo = Integer.parseInt(niaoYeBuffer[i]);
                    if (blo == 0) {
                        bloString = "-";
                    } else if (blo == 1) {
                        bloString = "+-";
                    } else if (blo == 2) {
                        bloString = "1+";
                    } else if (blo == 3) {
                        bloString = "2+";
                    } else if (blo == 4) {
                        bloString = "3+";
                    }
                    break;
                case 3:// 胆红素
                    int bil = Integer.parseInt(niaoYeBuffer[i]);
                    if (bil == 0) {
                        bilString = "-";
                    } else if (bil == 1) {
                        bilString = "1+";
                    } else if (bil == 2) {
                        bilString = "2+";
                    } else if (bil == 3) {
                        bilString = "3+";
                    }
                    break;
                case 4:// 酮体
                    int ket = Integer.parseInt(niaoYeBuffer[i]);
                    if (ket == 0) {
                        ketString = "-";
                    } else if (ket == 1) {
                        ketString = "+-";
                    } else if (ket == 2) {
                        ketString = "1+";
                    } else if (ket == 3) {
                        ketString = "2+";
                    } else if (ket == 4) {
                        ketString = "3+";
                    }
                    break;
                case 5:// 葡萄糖
                    int glu = Integer.parseInt(niaoYeBuffer[i]);
                    if (glu == 0) {
                        gluString = "-";
                    } else if (glu == 1) {
                        gluString = "+-";
                    } else if (glu == 2) {
                        gluString = "1+";
                    } else if (glu == 3) {
                        gluString = "2+";
                    } else if (glu == 4) {
                        gluString = "3+";
                    } else if (glu == 5) {
                        gluString = "4+";
                    }
                    break;
                case 6:// 蛋白质
                    int pro = Integer.parseInt(niaoYeBuffer[i]);
                    if (pro == 0) {
                        proString = "-";
                    } else if (pro == 1) {
                        proString = "+-";
                    } else if (pro == 2) {
                        proString = "1+";
                    } else if (pro == 3) {
                        proString = "2+";
                    } else if (pro == 4) {
                        proString = "3+";
                    }
                    break;
                case 7:// PH值
                    int ph = Integer.parseInt(niaoYeBuffer[i]);
                    if (ph == 0) {
                        phString = "5";
                    } else if (ph == 1) {
                        phString = "5.5";
                    } else if (ph == 2) {
                        phString = "6";
                    } else if (ph == 3) {
                        phString = "6.5";
                    } else if (ph == 4) {
                        phString = "7";
                    } else if (ph == 5) {
                        phString = "7.5";
                    } else if (ph == 6) {
                        phString = "8";
                    } else if (ph == 7) {
                        phString = "8.5";
                    } else if (ph == 8) {
                        phString = "9";
                    }
                    break;
                case 8:// 亚硝酸盐
                    int nit = Integer.parseInt(niaoYeBuffer[i]);
                    if (nit == 0) {
                        nitString = "-";
                    } else if (nit == 1) {
                        nitString = "1+";
                    }
                    break;
                case 9:// 白细胞
                    int leu = Integer.parseInt(niaoYeBuffer[i]);
                    if (leu == 0) {
                        leuString = "-";
                    } else if (leu == 1) {
                        leuString = "+-";
                    } else if (leu == 2) {
                        leuString = "1+";
                    } else if (leu == 3) {
                        leuString = "2+";
                    } else if (leu == 4) {
                        leuString = "3+";
                    }
                    break;
                case 10:// 比重
                    int sg = Integer.parseInt(niaoYeBuffer[i]);
                    if (sg == 0) {
                        sgString = "1.000";
                    } else if (sg == 1) {
                        sgString = "1.005";
                    } else if (sg == 2) {
                        sgString = "1.010";
                    } else if (sg == 3) {
                        sgString = "1.015";
                    } else if (sg == 4) {
                        sgString = "1.020";
                    } else if (sg == 5) {
                        sgString = "1.025";
                    } else if (sg == 6) {
                        sgString = "1.030";
                    }
                    break;
                case 11:// 维生素C
                    int asc = Integer.parseInt(niaoYeBuffer[i]);
                    if (asc == 0) {
                        ascString = "-";
                    } else if (asc == 1) {
                        ascString = "1+";
                    } else if (asc == 2) {
                        ascString = "2+";
                    } else if (asc == 3) {
                        ascString = "3+";
                    } else if (asc == 4) {
                        ascString = "+-";
                    }
                    break;
                default:
                    break;
            }
        }
        str_result = "尿胆原:" + uroString + ",潜血:" + bloString + ",胆红素:" + bilString + ",酮体:" + ketString + ",葡萄糖:"
                + gluString + ",蛋白质:" + proString + ",PH:" + phString + ",亚硝酸盐:" + nitString + ",白细胞:" + leuString
                + ",比重:" + sgString + ",维生素:" + ascString;
        // 验证重复数据
        if (!checkData("蛋白质", proString)) {
            // false 不保存数据
            return str_result;
        }

        UUID uuidNiaoYe = UUID.randomUUID();
        String dateNiaoYe = df.format(new Date());

        // 存尿胆原
        saveCLData("诺安尿液分析仪", "尿液分析仪", "尿胆原", uroString, "尿胆原", uuidNiaoYe.toString(), IDCARD, dateNiaoYe);
        // 存潜血
        saveCLData("诺安尿液分析仪", "尿液分析仪", "潜血", bloString, "潜血", uuidNiaoYe.toString(), IDCARD, dateNiaoYe);
        // 存胆红素
        saveCLData("诺安尿液分析仪", "尿液分析仪", "胆红素", bilString, "胆红素", uuidNiaoYe.toString(), IDCARD, dateNiaoYe);

        // 存酮体
        saveCLData("诺安尿液分析仪", "尿液分析仪", "酮体", ketString, "酮体", uuidNiaoYe.toString(), IDCARD, dateNiaoYe);
        // 葡萄糖
        saveCLData("诺安尿液分析仪", "尿液分析仪", "葡萄糖", gluString, "葡萄糖", uuidNiaoYe.toString(), IDCARD, dateNiaoYe);
        // 蛋白质
        saveCLData("诺安尿液分析仪", "尿液分析仪", "蛋白质", proString, "蛋白质", uuidNiaoYe.toString(), IDCARD, dateNiaoYe);
        // PH
        saveCLData("诺安尿液分析仪", "尿液分析仪", "PH", phString, "酸碱度", uuidNiaoYe.toString(), IDCARD, dateNiaoYe);
        // 亚硝酸盐
        saveCLData("诺安尿液分析仪", "尿液分析仪", "亚硝酸盐", nitString, "亚硝酸盐", uuidNiaoYe.toString(), IDCARD, dateNiaoYe);
        // 白细胞
        saveCLData("诺安尿液分析仪", "尿液分析仪", "白细胞", leuString, "白细胞", uuidNiaoYe.toString(), IDCARD, dateNiaoYe);
        // 比重
        saveCLData("诺安尿液分析仪", "尿液分析仪", "比重", sgString, "比重", uuidNiaoYe.toString(), IDCARD, dateNiaoYe);
        // 维生素
        saveCLData("诺安尿液分析仪", "尿液分析仪", "维生素", ascString, "维生素", uuidNiaoYe.toString(), IDCARD, dateNiaoYe);

        // HealthTiJian_FzjcFragment.showNiaoYeFenxi(proString, gluString,
        // ketString, bloString);
        return str_result;
    }

    /**
     * 保存测量数据
     *
     * @param device_name
     * @param device_type
     * @param cl_type
     * @param cl_value
     * @param cl_type_name
     * @param GUID
     * @param IDCARD
     * @param cl_time
     * @author 王婷婷
     * @date 2017年7月13日 下午5:40:20
     */
    public static void saveCLData(String device_name, String device_type, String cl_type, String cl_value,
                                  String cl_type_name, String GUID, String IDCARD, String cl_time) {
        SBCL_DATA sbcl_Data = new SBCL_DATA();
        sbcl_Data.setDEVICE_NAME(device_name);
        sbcl_Data.setDEVICE_TYPE(device_type);
        sbcl_Data.setCL_TYPE(cl_type);
        sbcl_Data.setCL_VALUE(cl_value);
        sbcl_Data.setCL_TYPE_NAME(cl_type_name);
        sbcl_Data.setGUID(GUID);
        sbcl_Data.setIDCARD(IDCARD);
        sbcl_Data.setCL_TIME(cl_time);
        sbcl_Data.setIS_UPDATE("Y");
        NovaApplication.fdbmanger.save(sbcl_Data);
    }

    /**
     * 验证数据
     *
     * @author 王婷婷
     * @date 2017年4月11日 下午4:48:40
     */
    private static boolean checkData(String cltype, String data) {
        boolean flag = true;
        List<SBCL_DATA> sbcl_data = NovaApplication.fdbmanger.findAllByWhere(SBCL_DATA.class,
                "IDCARD='" + IDCARD + "' and CL_TYPE='" + cltype + "'");

        if (sbcl_data.size() > 0) {
            String date_pre = sbcl_data.get(sbcl_data.size() - 1).getCL_TIME();
            String data_pre = sbcl_data.get(sbcl_data.size() - 1).getCL_VALUE();
            if (!TextUtils.isEmpty(date_pre)) {
                Log.w(TAG, date_pre);
                try {
                    long time_sec = ((new Date()).getTime() - (df.parse(date_pre)).getTime()) / 1000;
                    Log.w(TAG + time_sec, "tt" + time_sec);

                    if (cltype.equals(BluetoothConstant.NIAOJI_HT111A_HANTANG)) {
                        // 测量类型是尿机,小于5S不用验证数据结果
                        if (time_sec <= 5) {
                            flag = false;
                        }
                    } else {
                        if (time_sec <= 3 && data_pre.equals(data)) {
                            // 测量类型是血糖、血氧,小于3S验证数据结果
                            flag = false;
                        }
                    }

                } catch (ParseException e) {
                    e.printStackTrace();
                    flag = false;
                }
            }

        }

        return flag;
    }

}
